package cn.arikeky.order.service.impl;

import cn.arikeky.basic.util.CodeGenerateUtils;
import cn.arikeky.order.domain.OrderProduct;
import cn.arikeky.order.dto.OrderConfirmDto;
import cn.arikeky.order.dto.OrderProductDto;
import cn.arikeky.order.mapper.OrderProductMapper;
import cn.arikeky.order.service.IOrderProductService;
import cn.arikeky.basic.service.impl.BaseServiceImpl;
import cn.arikeky.org.domain.Shop;
import cn.arikeky.org.mapper.ShopMapper;
import cn.arikeky.product.domain.Product;
import cn.arikeky.product.mapper.ProductMapper;
import cn.arikeky.user.domain.User;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author arikeky
 * @since 2022-11-03
 */
@Service
public class OrderProductServiceImpl extends BaseServiceImpl<OrderProduct> implements IOrderProductService {
    @Autowired
    private OrderProductMapper orderProductMapper;

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private ShopMapper shopMapper;



    @Override
    public void userOrder(OrderProductDto orderProductDto, User user) {
        OrderProduct orderProduct = new OrderProduct();
        orderProduct.setUserId(user.getId());
        // 工具类生成订单sn
        orderProduct.setOrderSn(CodeGenerateUtils.generateOrderSn(user.getId()));
        orderProduct.setNum(1);
        orderProduct.setState(0);
        orderProduct.setProductId(orderProductDto.getId());

        Product product = productMapper.findById(orderProductDto.getId());
        orderProduct.setPrice(product.getSaleprice());
        Shop shop = shopMapper.findByName(orderProductDto.getShop().getName());
        orderProduct.setShopId(shop.getId());
        orderProduct.setDigest(orderProductDto.getName());
        orderProductMapper.add(orderProduct);

    }



    @Override
    public void confirm(OrderConfirmDto orderConfirmDto) {

    }

    @Override
    public void cancel(Long orderId) {

    }
}
